package edu.gatech.doi.spamframework.core;

import java.util.HashMap;

import edu.gatech.doi.spamframework.mapping.PropertiesFileOperator;
/**
 * Types of data sources 
 * maintain the mapping between data sources and data sources' type id. 
 * @author DE WANG
 *
 */
public class DataSourceTypes {


    /**
     * the operator of properties files
     */
	private static PropertiesFileOperator pfo=new PropertiesFileOperator(System.getProperties().getProperty("user.dir")+System.getProperties().getProperty("file.separator")+"properties"+System.getProperties().getProperty("file.separator")+"datasourcetypes.properties");
	
	/**
	 * obtain the value using the key
	 * @param key
	 * @return
	 */
	public static int get(String key)
	{
		int value;
		pfo.load();
		value=Integer.parseInt(pfo.getProperty(key.toUpperCase()));
		pfo.dispose();
		return value;
		
	}
	/**
	 * obtain the map of keys and values
	 * @return
	 */
	public static HashMap getMap()
	{
		pfo.load();
		HashMap hm=pfo.getPropertyMap();
		pfo.dispose();
		return hm;
		
	}
	/**
	 * create a new data source
	 * @param key
	 * @param value
	 */
	public static void newOne(String key,String value)
	{
		pfo.load();
		if(pfo.containsKey(key))
		{
			System.out.println("the key is already contained");
		}
		else
		{
			pfo.setProperty(key, value);
			pfo.save();
		
		}
		pfo.dispose();
	}
	/**
	 * delete a data source using the key
	 * @param key
	 */
	public static void delete(String key)
	{
		pfo.load();
		pfo.deleteProperty(key);
		pfo.save();
		pfo.dispose();
		
	}
	/**
	 * modify the data source
	 * @param key
	 * @param newvalue
	 */
	public static void modify(String key, String newvalue)
	{
		pfo.modifyProperty(key, newvalue);
		pfo.save();
		pfo.dispose();
	}
	
	
}
